<ix-modal-header [requiredRoles]="requiredRoles" [title]="title" [loading]="isFormLoading()"></ix-modal-header>

<mat-card>
  <mat-card-content>
    <form class="ix-form-container" [formGroup]="form" (submit)="onSubmit()">
      <ix-fieldset>
        <ix-input
          formControlName="comment"
          [label]="'Description' | translate"
        ></ix-input>

        <ix-select
          formControlName="type"
          [required]="true"
          [label]="'Type' | translate"
          [tooltip]="tooltips.type | translate"
          [options]="typeOptions$"
        ></ix-select>

        @if (isCommand$ | async) {
          <ix-input
            formControlName="command"
            [label]="'Command' | translate"
            [required]="true"
            [tooltip]="tooltips.command | translate"
          ></ix-input>
        } @else {
          <ix-explorer
            formControlName="script"
            [label]="'Script' | translate"
            [required]="true"
            [tooltip]="tooltips.script | translate"
            [nodeProvider]="treeNodeProvider"
            [canCreateDataset]="isNew"
          ></ix-explorer>
        }

        <ix-select
          formControlName="when"
          [label]="'When' | translate"
          [required]="true"
          [tooltip]="tooltips.when | translate"
          [options]="whenOptions$"
        ></ix-select>

        <ix-checkbox
          formControlName="enabled"
          [label]="'Enabled' | translate"
        ></ix-checkbox>

        <ix-input
          formControlName="timeout"
          type="number"
          [label]="'Timeout' | translate"
        ></ix-input>
      </ix-fieldset>

      <ix-form-actions>
        <button
          *ixRequiresRoles="requiredRoles"
          mat-button
          type="submit"
          color="primary"
          ixTest="save"
          [disabled]="form.invalid || isFormLoading()"
        >
          {{ 'Save' | translate }}
        </button>
      </ix-form-actions>
    </form>
  </mat-card-content>
</mat-card>
